﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ImageLib;
using System.Net;
using System.IO;

namespace ParserSkins
{
    class GalleryImageItem : ImageItem
    {
        ImageItemCollection gallery = new ImageItemCollection();

        public void AddGalleryImage(ImageItem imageItem)
        {
            gallery.Add(imageItem);
        }

        private string _path;
        public void Save(String path)
        {
            _path = path;
            if (Img != null && path != String.Empty)
            {
                try
                {
                    WebClient wc = new WebClient();
                    wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(SaveDataCompleted);
                    wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(SaveProgressChanged);
                    wc.DownloadDataAsync(new Uri(ImgUrl));
                }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
            }
        }

        public void SaveDataCompleted(object sender, DownloadDataCompletedEventArgs args)
        {
            try
            {
                if (!Directory.Exists(_path))
                {
                    Directory.CreateDirectory(_path);
                }
                FileStream fs = new FileStream(_path + "//" + Name, FileMode.Create);
                fs.Write(args.Result, 0, args.Result.Length);
                fs.Close();
                Advance = 145;
            }
            catch (Exception ex) { Console.WriteLine(ex.Message); }
        }
    }
}
